package com.sky.mapper;

import com.sky.dto.GoodsSalesDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

public interface OrdersMapper {

    /**
     * 添加订单信息
     *
     * @param orders
     */
    void insert(Orders orders);

    /**
     * 根据订单状态和当前时间-15分钟 查询数据
     *
     * @param status
     * @param orderTime
     * @return
     */
    @Select("select * from orders where status = #{status} and order_time < #{orderTime}")
    List<Orders> selectByStatusAndOrderTime(Integer status, LocalDateTime orderTime);

    /**
     * 修改订单信息
     *
     * @param orders
     */
    void update(Orders orders);

    /**
     * 根据条件查询当天营业额
     *
     * @param status
     * @param start
     * @param end
     * @return
     */
    @Select("select sum(amount) from orders where status = #{status} and order_time between #{start} and #{end}")
    Double sumByMap(Integer status, LocalDateTime start, LocalDateTime end);

    /**
     * 订单统计
     *
     * @param map
     */
    Integer countByMap(Map map);

    /**
     * 获取销量前十的菜品和套餐
     *
     * @param map
     * @return
     */
    @MapKey("name")
    List<GoodsSalesDTO> sumTop10(Map map);
}
